<?php

/**
 * @author shuang
 * @date 2016-10-26 10:28:41
 */
use yii\helpers\Url;
use yii\bootstrap\Html;
use common\components\MTools;
use yii\helpers\ArrayHelper;

$this->registerCssFile("/js/ui-dialog.css");
$this->registerJsFile("/js/dialog-plus-min.js", [\yii\web\JqueryAsset::className(), "depends" => "\yii\web\JqueryAsset"]);
$this->registerJsFile('/js/task.js', [\yii\web\JqueryAsset::className(), "depends" => "\yii\web\JqueryAsset"]);
$this->registerJs('task.bindFunc();');
echo $this->render("//layouts/breadcrumb", ["url" => Url::toRoute(["task/mywork"]), "title" => "我的任务"]);
?>
<div class="container-fluid">
    <div class="row-fluid">
        <div class="span12 well  ibox float-e-margins">
            <div class="ibox-title">我的任务</div>
            <div class="well-content  ibox-content">
                <form name="form1" method="post" action="<?php echo Url::toRoute(["mywork"]); ?>" id="form1">
                    <?php echo MTools::getTemplate("task-list-notice.html"); ?>
                    <div class="control-group">
                        <div class="controls">
                            <?php echo Html::dropDownList("status", $status, ArrayHelper::map(MTools::dictDropdown("task_status_type", true), "id", "name"), ["class" => "span3 left", "id" => "statusType", "style" => "float:left;"]); ?>
                            <?php echo Html::textInput("title", $title, ["class" => "span3", "placeholder" => "输入任务名称", "style" => "float:left;margin:0 10px;"]); ?>
                            <?php echo Html::submitButton("搜索", ["id" => "search", "class" => "left btn btn-success", "style" => "padding:5px 12px;"]); ?>
                            <?php echo Html::a("刷新", Url::toRoute("mywork"),["id" => "reflashbtn", "class" => "pull-right btn", "style" => "padding:5px 12px;"]); ?>
                        </div>
                    </div>
                </form>
                <div class="clearfix"></div>
                <div class="table-responsive">
                    <div id="table1_wrapper" class="dataTables_wrapper no-footer">
                        <table id="table1" class="table dataTable no-footer fixed_headers" >
                            <thead>
                                <tr>
                                    <th style="width: 5%">编号</th>
                                    <th style="width: 30%">任务名称</th>
                                    <th style="width: 10%">总需求量/隐藏</th>
                                    <th style="width: 5%">已完成</th>
                                    <th style="width: 5%">不合格</th>
                                    <th style="width: 7%">状态</th>
                                    <th style="width: 8%;text-align: center;">创建时间</th>
                                    <th style="width: 16%;text-align: center;">操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php if ($topdata): ?>
                                    <?php foreach ($topdata as $item): ?>
                                        <tr>
                                            <td><?php echo ArrayHelper::getValue($item, "id") ?></td>
                                            <td><?php echo ArrayHelper::getValue($item, "title") ?><span class='redcolor'>[置顶]</span><?php echo ArrayHelper::getValue($item, "is_speed") == 1 ? "<span class='redcolor'>[限速]</span>" : null; ?></td>
                                            <td><?php echo MTools::IntFormat(ArrayHelper::getValue($item, "number")) . "/" . MTools::IntFormat(ArrayHelper::getValue($item, "hidcount")) ?></td>
                                            <td><?php echo MTools::IntFormat(ArrayHelper::getValue($item, "stacount")) ?></td>
                                            <td><?php echo MTools::IntFormat(ArrayHelper::getValue($item, "comcount")) ?></td>
                                            <td><?php echo Yii::$app->formatter->asText(ArrayHelper::getValue($item, "statusname")) ?></td>
                                            <td><?php echo Yii::$app->formatter->asDatetime(ArrayHelper::getValue($item, "created_at")) ?></td>
                                            <td class="center" style="padding: 6px;text-align: center;">
                                                <a style="padding: 8px 12px;" class="btn btn-success" href="<?php echo Url::toRoute(["task/showwork", "id" => ArrayHelper::getValue($item, "id")]); ?>">查图</a>
                                                <div class="btn-group mr5">
                                                    <button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown">
                                                        功能 <span class="caret"></span>
                                                    </button>
                                                    <ul class="dropdown-menu dropdown-menu-function" role="menu">
                                                        <li><a href="javascript:;" data-action="zhuijia" data-url="<?php echo Url::toRoute(["task/zhuijia", "id" => ArrayHelper::getValue($item, "id")]); ?>">追加任务数量</a></li>
                                                        <li><a href="javascript:;" data-action="xiansu" data-url="<?php echo Url::toRoute(["task/xiansu", "id" => ArrayHelper::getValue($item, "id")]); ?>">限制投票速度</a></li>
                                                        <li><a href="javascript:;" data-action="copy" data-url="<?php echo Url::toRoute(["task/copy", "id" => ArrayHelper::getValue($item, "id")]); ?>">复制任务</a></li>
                                                        <li><a href="javascript:;" data-action="update" data-url="<?php echo Url::toRoute(["task/update", "id" => ArrayHelper::getValue($item, "id")]); ?>">编辑任务</a></li>
                                                        <li><a href="javascript:;" data-action="tasktop" data-url="<?php echo Url::toRoute(["task/tasktop", "id" => ArrayHelper::getValue($item, "id")]); ?>">任务置顶</a></li>
                                                        <li><a href="javascript:;" data-action="autoreflash" data-url="<?php echo Url::toRoute(["task/autoreflash", "id" => ArrayHelper::getValue($item, "id")]); ?>">自动刷新任务</a></li>
                                                        <li><a href="javascript:;" data-action="reflash" data-url="<?php echo Url::toRoute(["task/reflash", "id" => ArrayHelper::getValue($item, "id")]); ?>">刷新任务</a></li>
                                                    </ul>
                                                </div>
                                                <?php if ($item["status"] != 67): ?>
                                                    <?php if ($item["ispack"] == 1): ?>
                                                        <a  style="padding: 8px 12px;" class="btn btn-warning" data-id="<?php echo ArrayHelper::getValue($item, "id"); ?>" data-action="dabaodownload">打包下载</a>
                                                    <?php else: ?>
                                                        <a  style="padding: 8px 12px;" class="btn btn-warning operateTask" data-id="<?php echo ArrayHelper::getValue($item, "id"); ?>" data-action="dabao">打包</a>
                                                    <?php endif; ?>
                                                <?php else: ?>
                                                    <a  style="padding: 8px 12px;" class="btn btn-warning operateTask" data-id="<?php echo ArrayHelper::getValue($item, "id"); ?>" data-action="stoptask">停止</a>
                                                <?php endif; ?>
                                            </td>
                                        </tr>
                                    <?php endforeach; ?>
                                <?php endif; ?>
                                <?php foreach ($data as $item): ?>
                                    <tr>
                                        <td><?php echo ArrayHelper::getValue($item, "id") ?></td>
                                        <td><?php echo ArrayHelper::getValue($item, "title") ?><?php echo ArrayHelper::getValue($item, "is_speed") == 1 ? "<span class='redcolor'>[限速]</span>" : null; ?></td>
                                        <td><?php echo MTools::IntFormat(ArrayHelper::getValue($item, "number")) . "/" . MTools::IntFormat(ArrayHelper::getValue($item, "hidcount")) ?></td>
                                        <td><?php echo MTools::IntFormat(ArrayHelper::getValue($item, "stacount")) ?></td>
                                        <td><?php echo MTools::IntFormat(ArrayHelper::getValue($item, "comcount")) ?></td>
                                        <td><?php echo Yii::$app->formatter->asText(ArrayHelper::getValue($item, "statusname")) ?></td>
                                        <td><?php echo Yii::$app->formatter->asDatetime(ArrayHelper::getValue($item, "created_at")) ?></td>
                                        <td class="center" style="padding: 6px;text-align: center;">
                                            <a style="padding: 8px 12px;" class="btn btn-success" href="<?php echo Url::toRoute(["task/showwork", "id" => ArrayHelper::getValue($item, "id")]); ?>">查图</a>
                                            <div class="btn-group mr5">
                                                <button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown">
                                                    功能 <span class="caret"></span>
                                                </button>
                                                <ul class="dropdown-menu dropdown-menu-function" role="menu">
                                                    <li><a href="javascript:;" data-action="zhuijia" data-url="<?php echo Url::toRoute(["task/zhuijia", "id" => ArrayHelper::getValue($item, "id")]); ?>">追加任务数量</a></li>
                                                    <li><a href="javascript:;" data-action="xiansu" data-url="<?php echo Url::toRoute(["task/xiansu", "id" => ArrayHelper::getValue($item, "id")]); ?>">限制投票速度</a></li>
                                                    <li><a href="javascript:;" data-action="copy" data-url="<?php echo Url::toRoute(["task/copy", "id" => ArrayHelper::getValue($item, "id")]); ?>">复制任务</a></li>
                                                    <li><a href="javascript:;" data-action="update" data-url="<?php echo Url::toRoute(["task/update", "id" => ArrayHelper::getValue($item, "id")]); ?>">编辑任务</a></li>
                                                    <li><a href="javascript:;" data-action="tasktop" data-url="<?php echo Url::toRoute(["task/tasktop", "id" => ArrayHelper::getValue($item, "id")]); ?>">任务置顶</a></li>
                                                    <li><a href="javascript:;" data-action="autoreflash" data-url="<?php echo Url::toRoute(["task/autoreflash", "id" => ArrayHelper::getValue($item, "id")]); ?>">自动刷新任务</a></li>
                                                    <li><a href="javascript:;" data-action="reflash" data-url="<?php echo Url::toRoute(["task/reflash", "id" => ArrayHelper::getValue($item, "id")]); ?>">刷新任务</a></li>
                                                </ul>
                                            </div>
                                            <?php if ($item["status"] != 67): ?>
                                                <?php if ($item["ispack"] == 1): ?>
                                                    <a  style="padding: 8px 12px;" class="btn btn-warning" data-id="<?php echo ArrayHelper::getValue($item, "id"); ?>" data-action="dabaodownload">打包下载</a>
                                                <?php else: ?>
                                                    <a  style="padding: 8px 12px;" class="btn btn-warning operateTask" data-id="<?php echo ArrayHelper::getValue($item, "id"); ?>" data-action="dabao">打包</a>
                                                <?php endif; ?>
                                            <?php else: ?>
                                                <a  style="padding: 8px 12px;" class="btn btn-warning operateTask" data-id="<?php echo ArrayHelper::getValue($item, "id"); ?>" data-action="stoptask">停止</a>
                                            <?php endif; ?>
                                        </td>
                                    </tr>
                                <?php endforeach; ?>
                            </tbody>
                        </table>
                    </div>
                    <div class="pagination" style="float:right;">
                        <?php
                        echo
                        \yii\widgets\LinkPager::widget([
                            'pagination' => $pager,
                            'nextPageLabel' => '下一页',
                            'prevPageLabel' => '上一页',
                        ]);
                        ?>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>